using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Autenticazione;
namespace BusinessObject
{
	public class Coach
	{
		public string EMail;
		public long Line;
		public string FullName;
		public string Phone;
		public Coach()
		{
		}
		public Coach(string email, long line, string fullName, string phone)
		{
			this.EMail = email;
			this.Line = line;
			this.FullName = fullName.Replace("'", "''");
			this.Phone = phone;
		}
		public DataTable GetTbCoaches(string email)
		{
			string strSQL = string.Format("select * from Allenatore where Email = '{0}' order by FullName", email);
			DB db = new DB();
			return db.GetTable(strSQL);
		}
		public List<Coach> GetCoaches(string email)
		{
			List<Coach> coaches = new List<Coach>();
			string strSQL = string.Format("select * from Allenatore where Email = '{0}' order by FullName", email);
			DB db = new DB();
			SqlDataReader dr = db.Reader(strSQL);
			if (dr == null)
			{
				return coaches;
			}
			while (dr.Read())
			{
				coaches.Add(new Coach(dr["Email"].ToString(), long.Parse(dr["Line"].ToString()), dr["FullName"].ToString(), dr["Phone"].ToString()));
			}
			db.CloseConnection();
			return coaches;
		}
		public bool DeleteCoach()
		{
			string strSQL = string.Format("delete from Allenatore where Line = {0}", this.Line.ToString());
			DB db = new DB();
			return db.ExecuteNonQuery(strSQL);
		}
		public bool Salva()
		{
			string strSQL = string.Format("insert into Allenatore (EMail, FullName, Phone) values ('{0}','{1}', '{2}')", this.EMail, this.FullName, this.Phone);
			DB db = new DB();
			return db.ExecuteNonQuery(strSQL);
		}
		public bool Update()
		{
			string strSQL = string.Format("update Allenatore set FullName = '{0}', Phone = '{1}' where Line = {2}", this.FullName, this.Phone, this.Line.ToString());
			DB db = new DB();
			return db.ExecuteNonQuery(strSQL);
		}
	}
}
